/**
 来电弹屏显示
 **/

$(document).ready(function(){
	//初始化来电弹屏所有字典项方法
	initializeDictionary();
	//加载客户信息区域字典值
	setCustomerInformationDictionary();
	//设置新建客服工单编码
	// setCsWoCustSerCode();
	//新建工单字典项加载
	setCsSmOrderDictionary();
	//来电手机号查询方法
	queryBytelcustomerInformation();
	//初始化显示提交按钮
	hideCsSmOrderButton();
	//tab事件按钮(重启，催办，提交)隐藏显示
	tabCsSmOrder();
});

/******************* 来电弹屏单击方法功能区域------开始-----------*author：chutianhua* date:2018/6/26* update* ***************************************/
//声明客户信息全局变量（判断客户信息是够存在）
var isNoCustomerInfomationHave;
function  addInfomation(){
	//校验客户信息和新建工单信息
	var customerInfomationFormValidate = $("#CustomerInformmationFromId").form("validate");
	var csWoCusterFormValidate = $("#addCsSmOrderForm").form("validate");
	if(customerInfomationFormValidate == true && csWoCusterFormValidate == true){
		if($('#customerTelId').textbox('getValue') != $('#phoneId').val()){
			showInfoMsg("请先查询客户信息");
			return;
		}
		$('#addCsSmOrderId').linkbutton('disable');//置灰提交按钮
		//提交按钮（负责客户信息保存和新建工单信息保存）
		if(isNoCustomerInfomationHave == "Yes"){
			//客户信息存在且用户可能需要修改客户信息
			//判断客户信息表单数据是否发生变化
			var newData = getFormData("CustomerInformmationFromId");
			var formChange =  comparsionFormData(usedData,newData);
			if(formChange){
				//先执行修改客户信息方法,返回保存状态 true,false
				updateCoustomerInformation();
			}else{
				//表单信息不发生变化，直接执行工单保存
				saveorsubmitCsWoCustSer();
			}
		} else if(isNoCustomerInfomationHave == "No"){
			//客户信息不存在，所有先保存客户信息才能保存工单信息
			 saveCoustomerInformation();
		}
	}
}
/******************* 来电弹屏单击方法功能区域------结束-----------*author：chutianhua* date:2018/6/26* update* ***************************************/





/******************* 来电弹屏来电数据加载-信息功能区域------开始-----------*author：chutianhua* date:2018/6/26* update* ***************************************/

/***
 * 来电信息查询功能区域----核心功能
 * author:chutianhua
 * date:2018/6/26
 * **/
function queryBytelcustomerInformation(){
	var customerTel = $('#customerTelId').textbox('getValue') == "" ? 0 : $('#customerTelId').textbox('getValue');
	//验证不通过，重置页面
	if(!$('#customerTelId').textbox('isValid')){
		customerTel = 0;
	}
	var url =G_CTX_PATH+'/cs/CsCustomerInfomation/getCustomerInformationQueryPhone.do';
	uceAjax(url,{phone:customerTel},function(data){
		var result = data;
		if(result.success){
			//已完结工单参数
			var haveDoneParams = {
				customerTel: customerTel,
				status: "5",
				source:"0"
			}

			//处理中工单参数
			var noDoneWorkParams = {
				customerTel: customerTel,
				statusMul: "0,1,2,3,4",
				source:"0"
			}

			//判断当前关联手机号客户信息是否存在
			if(result.data!=null){
				//来电手机号客户信息存在
				haveDoneWorkListLoading(haveDoneParams); //已完结工单列表加载
				noDoneWorkListLoading(noDoneWorkParams);//处理中工单列表加载
				setCustomerInformation(result.data);  //设置客户信息回填数据
				//客户信息存在状态
				isNoCustomerInfomationHave = "Yes";
			}else{
				//来电手机号客户信息不存在
				//没有客户信息，清空表单数据
				clearForm("CustomerInformmationFromId");
				customerTel != 0 ? $("#phoneId").val(customerTel) : $("#phoneId").val("");//设置客户信息区域--客户手机号值
				setCustomerCode();//设置客户信息区域客户编码
				haveDoneWorkListLoading(haveDoneParams); //已完结工单列表加载
				noDoneWorkListLoading(noDoneWorkParams);//处理中工单列表加载
				//客户信息不存在状态
				isNoCustomerInfomationHave = "No";
			}

		}

	});
}

/**
 * 客户信息查询
 */
function queryCustomerInformation(){
	var customerTel = $('#customerTelId').textbox('getValue') == "" ? 0 : $('#customerTelId').textbox('getValue');
	var url =G_CTX_PATH+'/cs/CsCustomerInfomation/getCustomerInformationQueryPhone.do';
	uceAjax(url,{phone:customerTel},function(data){
		var result = data;
		if(result.success){
			//判断当前关联手机号客户信息是否存在
			if(result.data!=null){
				//来电手机号客户信息存在
				setCustomerInformation(result.data);  //设置客户信息回填数据
				//客户信息存在状态
				isNoCustomerInfomationHave = "Yes";
			}else{
				//来电手机号客户信息不存在
				//没有客户信息，清空表单数据
				clearForm("CustomerInformmationFromId");
				customerTel != 0 ? $("#phoneId").val(customerTel) : $("#phoneId").val("");//设置客户信息区域--客户手机号值
				setCustomerCode();//设置客户信息区域客户编码
				//客户信息不存在状态
				isNoCustomerInfomationHave = "No";
			}
		}
	});
}


/***
 * 来电查询客户信息字段回填方法功能区域
 * author:chutianhua
 * date:2018/6/27
 * **/
var usedData;
var custPCCT = {};//客户省市区镇
var senderPCCT = {};//发件人省市区镇
var receiverPCCT = {};//寄件人省市区镇
function setCustomerInformation(date) {
	if (date != null) {
		//调用客户信息字典项加载方法,设置客户类型,等级,性别
		setCustomerInformationDictionary((date.custType).toString(),(date.custGrade).toString(),(date.custSex).toString());
		//设置客户信息值
		$('#customerInformationId').val(date.id);//客户id
		$('#phoneId').val(date.phone);//客户电话
		$('#customerCodeId').textbox('setValue', date.custCode);//客户编码
		$('#customerInformmationNameId').textbox('setValue', date.custName);//客户姓名
		$('#customerInformationLabelId').textbox('setValue', date.custLabel);//客户标签
		//设置行政区划回填
		/*$("#customerInformmationProvinceSelectId").combobox('setValue', date.province);
		 $("#customerInformmationCitySelectId").combobox('setValue', date.city);
		 $("#customerInformmationCountySelectId").combobox('setValue', date.county);
		 $("#townId").combobox('setValue', date.town);
		 */
		custPCCT["provinces"] = date.province;
		custPCCT["citys"] = date.city;
		custPCCT["countys"] = date.county;
		custPCCT["towns"] = date.town;

		usedData = getFormData("CustomerInformmationFromId");
	}

}
/******************* 来电弹屏来电数据加载-信息功能区域-------------结束----------- *  author：chutianhua  * date:2018/6/26* update* ***************************************/


/******************* 客户信息功能区域开始*author：chutianhua* date:2018/6/26* update* ***************************************/

/***
 * 客户信息保存方法功能区域
 * author:chutianhua
 * date:2018/6/26
 * **/
function saveCoustomerInformation() {
	//校验客户手机号
	// var custmoerTel = $("#customerTelId").textbox("getText");
	// var isExist = checkCustomerPhone(custmoerTel);
	// if (isExist) {
	// 	showInfoMsg("该手机号已存在");
	// 	return;
	// } else {
		//客户信息冗余字段
		saveRedundancyText();
		var url = G_CTX_PATH + "/cs/CsCustomerInfomation/csCustomerInformationAdd.do";
		var date = serializeFormObj("CustomerInformmationFromId");
		uceAjax(url,date,function(res){
			if (res.rows == "1") {
				//设置客户信息id
				$("#customerInformationId").val(res.id);
				//保存成功直接保存新建工单
				saveorsubmitCsWoCustSer();
			} else if (res.rows == "0") {
				showInfoMsg("客户信息保存失败！");
				$('#addCsSmOrderId').linkbutton('enable');
			}
		});
	// }
}
/***
 * 客户信息修改方法功能区域
 * author:chutianhua
 * date:2018/6/26
 * **/
function updateCoustomerInformation() {
	//客户信息冗余字段
	saveRedundancyText();
	var url = G_CTX_PATH + "/cs/CsCustomerInfomation/customerInformationuUpd.do";
	var date = serializeFormObj("CustomerInformmationFromId");
	uceAjax(url,date,function(res){
		if (res.success) {
			if(res.data == 1){
				//保存成功直接保存新建工单
				saveorsubmitCsWoCustSer();
			} else if (res.data == 0) {
				showInfoMsg("客户信息修改失败！！");
				$('#addCsSmOrderId').linkbutton('enable');
			}
		}
	});
}

/***
 * 客户信息相关字典项加载方法功能区域
 * author:chutianhua
 * date:2018/6/26
 * **/
function setCustomerInformationDictionary(customerTypeSelect,customerGrade,customerSex) {
	//去掉combobox初始化默认值
	var customerTypeParams = {
		headerValue:false,
		value:customerTypeSelect
	}
	var customerGradeParams = {
		headerValue:false,
		value:customerGrade
	}
	var sexParams = {
		headerValue:false,
		value:customerSex
	}
	//设置客户类型
	uceDictCombobox("customerInformationCustomerTypeSelectId","CUSTOMER_TYPE",customerTypeParams);
	//设置客户等级
	uceDictCombobox("customerInformationCustomerGradeSelectId","CUSTOMER_GRADE",customerGradeParams);
	//设置客户性别
	uceDictCombobox("customerInformationSexSelectId","SYS_SEX",sexParams);
	//设置行政区划值,调用公共方法
	setAdministrativeDivisionValue(custPCCT,"customerInformmationProvinceSelectId","customerInformmationCitySelectId", "customerInformmationCountySelectId", "townId");
}

/***
 * 客户信息设置客户编码值方法功能区域
 * author:chutianhua
 * date:2018/6/26
 * **/
function setCustomerCode() {
	var url = G_CTX_PATH + '/cs/HomeScreenPopup/getCustomer.do';
	$.ajax({
		type: 'get',
		url: url,
		success: function (data) {
			var jsonObject = $.parseJSON(data);
			$.each(jsonObject, function (index, row) {
				$('#customerCodeId').textbox('setValue', row.Customer);
			});
		}
	});
}

/***
 * 客户信息保存相关字段的冗余字段方法功能区域
 * author:chutianhua
 * date:2018/6/26
 * **/
function saveRedundancyText() {
	//保存省冗余字段值
	var provinceText = $('#customerInformmationProvinceSelectId').combobox('getText');
	$('#provinceNameId').val(provinceText);
	//保存市冗余字段值
	var cityText = $('#customerInformmationCitySelectId').combobox('getText');
	$('#cityNameId').val(cityText);
	//保存县区冗余字段值
	var countyText = $('#customerInformmationCountySelectId').combobox('getText');
	$('#countyNameId').val(countyText);
	//保存乡镇冗余字段值
	var townText = $('#townId').combobox('getText');
	$('#townNameId').val(townText);
}

/******************* 客户信息功能区域结束*author：chutianhua* date:2018/6/26* update* ***************************************/


/******************* 已处理和已完结工单和tab页事件功能区域--- 开始---*author：chutianhua* date:2018/6/26** ***************************************/
/***
 * 处理编辑，催办，重启按钮隐藏功能区域
 * author:chutianhua
 * date:2018/6/27
 * **/
function hideCsSmOrderButton(){
	$("#CsSmOrderIdPress").hide();
	$("#CsSmOrderIdcq").hide();
	$("#addCsSmOrderId").show();

}
/***
 * 处理编辑，催办,重启按钮显示功能区域
 * author:chutianhua
 * date:2018/6/27
 * **/
function showCsSmOrderButton(){
	$("#CsSmOrderIdPress").show();
	$("#CsSmOrderIdcq").hide();
	$("#addCsSmOrderId").hide();
}
/***
 * 处理编辑，催办，重启按钮显示功能区域
 * author:chutianhua
 * date:2018/6/27
 * **/
function showCsSmOrderButtoncq(){
	$("#CsSmOrderIdPress").hide();
	// $("#CsSmOrderIdcq").show();
	$("#addCsSmOrderId").hide();
}
/***
 * tab事件加载功能区域
 * author:chutianhua
 * date:2018/6/27
 * **/
function tabCsSmOrder(){
	$('#CsSmOrdeTabs').tabs({
		onSelect:function(title,index){
			if(index=="0"){
				hideCsSmOrderButton();
			}else if(index=='1'){
				showCsSmOrderButton();
			}else if(index=='2'){
				showCsSmOrderButtoncq();
			}
		}
	});
}
/***
 * 已完成列表重启功能方法功能区域
 * author:chutianhua
 * date:2018/6/27
 *
 * **/
function restartCsWoCustSerWork(){
	var row = $("#haveDoneWorkList").datagrid("getSelected");
	if (!row){
		showInfoMsg("请选择一条记录!");
		return;
	}else{
		showInfoMsg("尚在开发中......!", function(){
			/*var ids = row.id;
			 openTabCrossDomainIcsSimple("perssioncoderlliu","服务类工单编辑页面","/cs/CsWoCustSer/detail/"+ids,false,0,portal_global_systemCode,false);*/

		});
	}
}
/***
 * 处理中工单和已完结工单工单流转信息弹窗显示功能方法功能区域
 * author:chutianhua
 * date:2018/6/27
 *
 * **/
function dlgCsWorkOrder(woCode){
	$('#dlgCsWoWorkOrderId').dialog({
		title : '工单流转详情',
		iconCls:'icon-title',
		cache : false,
		modal : true,
		constrain:true,
		resizable:true,
		shadow:false,
		onOpen : function() {
			workOrderDealwithFlow(woCode);
		}
	});
	$('#dlgCsWoWorkOrderId').dialog('open');
	//调整弹出框位置
	movePanel('dlgCsWoWorkOrderId',50,150);
}

/***
 * 工单处理流转信息列表功能方法功能区域
 * author:chutianhua
 * date:2018/6/27
 *
 * **/
function workOrderDealwithFlow(woCodes){
	var columns = [[
		{field:'operationName',title: '名称', width: 100},
		{field:'createTime',title: '创建时间',width: 130,formatter:function(value,row,index){
			return  formatData(value)
		}},
		{field:'submitTime',title: '处理时间',width: 130,formatter:function(value,row,index){
			return  formatData(value)
		}},
		{field:'handlerDepartName',title: '处理部门', width: 100},
		{field:'currentHandlerName',title: '处理人', width: 100},
		{field:'handleExplain',title: '跟踪记录',formatter: formatTip}
	]]
	var dataGridParams = {
		url:G_CTX_PATH+"/cs/HomeScreenPopup/getHandleRecords.do",
		Method:'POST',
		queryParams:{woCode:woCodes},
		fitColumns : 'false'
	}
	newloadGrid('csWoWorkOrderListId', columns, dataGridParams);
}
/***
 * 关闭处理中和完结工单工单流转记录弹窗功能方法功能区域
 * author:chutianhua
 * date:2018/6/27
 *
 * **/
function closeDlgCsWoWorkOrder(){
	$('#dlgCsWoWorkOrderId').window('close');
}
/***
 * easyui-Panel 调节弹出窗位置功能方法功能区域
 * author:chutianhua
 * date:2018/6/27
 *
 * **/
function movePanel(id,top,left){
	id == "" ? console.error('元件为空') : $("#"+id).panel('move',{top:top, left:left});
}

/***
 * 处理中工单列表加载功能区域
 * author:chutianhua
 * date:2018/6/26
 * **/
function noDoneWorkListLoading(params) {
	var columns = [[
		{field: 'ck', checkbox: true, resizable: true, align: 'center'},
		{
			field: 'deal', title: '工单流转信息', width: 120, align: 'center', formatter: function (value, row, index) {
			//预留方法查询工单流程信息
			var woCode = row.code;
			var ret = '<a href="javascript:void(0)" onclick="dlgCsWorkOrder(\'' + woCode + '\')">预览</a>';
			return ret;
		}
		},
		{field: 'code', title: '工单编号', width: 100, align: 'center', formatter: formatTip},
		{field: 'waybillNum', title: '运单编号', width: 100, align: 'center', formatter: formatTip},
		{
			field: 'priority', title: '优先级', width: 80, align: 'center', formatter: function (value) {
			return getTypeNameByCode("PRCESS_PRIORITY_PROCESSING", value, formatTip);
		}
		},
		{field: 'urgeNum', title: '催办次数', width: 80, align: 'center', formatter: formatTip},
		{
			field: 'status', title: '状态', width: 80, align: 'center', formatter: function (value) {
			return getTypeNameByCode("CUST_SER_STATUS", value, formatTip);
		}
		},
		{field: 'orderTypeName', title: '工单类型', align: 'center', width: 80, formatter: formatTip},
		{field: 'orderChilTypeName', title: '工单子类型', align: 'center', width: 80, formatter: formatTip},
		{field: 'submitterName', title: '工单发起人', align: 'center', width: 80, formatter: formatTip},
		{field: 'acceptServicerName', title: '受理客服', align: 'center', width: 80, formatter: formatTip},
		{
			field: 'createTime', title: '创建时间', align: 'center', width: 100, formatter: function (value) {
			return formatData(value)
		}
		}

	]];
	var dataGridParams = {
		url: G_CTX_PATH + "/cs/CsWoCustSer/getCsWoCustSerVoList.do",
		queryParams: params,
		fitColumns: 'true',
		rownumbers: 'false',
		singleSelect: 'true',
		onLoadSuccess: function (param) {
			var rows = $('#nohaveDoneWorkList').datagrid('getRows');
			var noDoneWorkListNum = rows.length;
			var tab = $('#CsSmOrdeTabs').tabs('getTab', 1);//获取tab的标题
			var noDoneWorkListTitle = "处理中工单<strong>0</strong>";
			if (noDoneWorkListNum > 0) {
				noDoneWorkListTitle = "处理中工单<strong>" + noDoneWorkListNum + "</strong>";
				$('#CsSmOrdeTabs').tabs('select',1);
			}
			$('#CsSmOrdeTabs').tabs('update', {
				tab: tab,
				options: {
					title: noDoneWorkListTitle
				}
			});
		}
	};
	newloadGrid('nohaveDoneWorkList', columns, dataGridParams);
}
/***
 * 已完结工单列表加载功能区域
 * author:chutianhua
 * date:2018/6/26
 * **/
function haveDoneWorkListLoading(params) {
	var columns = [[
		{field: 'ck', checkbox: true, resizable: true, align: 'center'},
		{
			field: 'deal', title: '工单流转信息', align: 'center', width: 80, formatter: function (value, row, index) {
			//预留方法查询工单流程信息
			var woCode = row.code;
			var ret = '<a href="javascript:void(0)" onclick="dlgCsWorkOrder(\'' + woCode + '\')">预览</a>';
			return ret;
		}
		},
		{field: 'code', title: '工单编号', width: 100, align: 'center', formatter: formatTip},
		{field: 'waybillNum', title: '运单编号', width: 100, align: 'center', formatter: formatTip},
		{
			field: 'priority', title: '优先级', width: 80, align: 'center', formatter: function (value) {
			return getTypeNameByCode("PRCESS_PRIORITY_PROCESSING", value, formatTip);
		}
		},
		{field: 'urgeNum', title: '催办次数', width: 80, align: 'center', formatter: formatTip},
		{
			field: 'status', title: '状态', width: 80, formatter: function (value) {
			return getTypeNameByCode("CUST_SER_STATUS", value, formatTip);
		}
		},
		{field: 'orderTypeName', title: '工单类型', align: 'center', width: 80, formatter: formatTip},
		{field: 'orderChilTypeName', title: '工单子类型', align: 'center', width: 80, formatter: formatTip},
		{field: 'submitterName', title: '工单发起人', align: 'center', width: 80, formatter: formatTip},
		{field: 'acceptServicerName', title: '受理客服', align: 'center', width: 80, formatter: formatTip},
		{
			field: 'createTime', title: '创建时间', align: 'center', width: 100, formatter: function (value) {
			return formatData(value)
		}
		}

	]];

	var dataGridParams = {
		url: G_CTX_PATH + "/cs/CsWoCustSer/getCsWoCustSerVoList.do",
		queryParams: params,
		fitColumns: 'true',
		rownumbers: 'false',
		singleSelect: 'true',
		onLoadSuccess: function (param) {
			var rows = $('#haveDoneWorkList').datagrid('getRows');
			var completedWorkListNum = rows.length;
			var tab = $('#CsSmOrdeTabs').tabs('getTab', 2);//获取tab的标题
			var completedWorkListTitle = "已完结工单<strong>0</strong>";
			if (completedWorkListNum > 0) {
				completedWorkListTitle = "已完结工单<strong>" + completedWorkListNum + "</strong>";
			}
			$('#CsSmOrdeTabs').tabs('update', {
				tab: tab,
				options: {
					title: completedWorkListTitle
				}
			});
		},

	};
	newloadGrid('haveDoneWorkList', columns, dataGridParams);
}
/***
 * 处理中列表催办弹窗功能方法功能区域
 * author:chutianhua
 * date:2018/6/27
 *
 * **/
function urgeCsWoCustSer() {
	var row = $("#nohaveDoneWorkList").datagrid("getSelected");
	if (!row){
		showInfoMsg("请选择一条记录!");
		return;
	}else if(row.status=="-1"){
		showInfoMsg("工单未提交，不能催办!");
	}else if(row.status=="5"){
		showInfoMsg("工单处理完成，不能催办!");
	}else{
		$('#formUrge #urgeExplain').textbox('setValue','');
		$("#dlgUrge [name ='woCode']" ).val(row.woCode);
		createDialog("dlgUrge", '工单催办');
	}
}
/***
 * 处理中列表催办记录保存功能方法功能区域
 * author:chutianhua
 * date:2018/6/27
 *
 * **/
function urgeSave() {
	var formUrgeValidate = $("#formUrge").form('validate');
	if (formUrgeValidate) {
		var urgeData = serializeFormObj("formUrge");
		uceAjax(G_CTX_PATH + "/cs/CsWoCustSer/urge.do", urgeData, function (result) {
			if (result.success) {
				showInfoTip("催办成功");
				//关闭弹窗
				closeDialog('dlgUrge');
				$('#nohaveDoneWorkList').datagrid('load');
			}
		}, "POST");
	}
}

/**保存和提交前校验
 * 工单创建规则校验，
 * 呼叫中心工单：同一个来电号码，同一个运单，同一个类型，不可创建同类工单
 * */
function checkSameCsWoCustSer(){
	var same =false;
	var url = G_CTX_PATH + "/cs/CsWoCustSer/checkSameCsWoCustSer.do";
	var checkData ={
		orderType:$("#newCsSmOrderFromId  #orderTypeId").combobox("getValue"),
		orderChilType:$("#newCsSmOrderFromId  #orderChilTypeId").combobox("getValue"),
		waybillNum: $("#newCsSmOrderFromId #csSmOrderWaybillNumId").val(),
		customerTel:$("#newCsSmOrderFromId #customerTelId").val(),
		source:0
	}
	$.ajax({
		type: "GET",
		url: url,
		data: checkData,
		async: false,
		success : function(result){
			if(result.data==1){
				same=true;
			}
		}
	});
	return same;
}
/******************* 已处理和已完结和tab页事件工单功能区域--- 结束---*author：chutianhua* date:2018/6/26** ***************************************/

/******************* 新建工单功能区域--- 开始---*author：chutianhua* date:2018/6/26** ***************************************/
/***
 * 新建工单字典项加载功能方法功能区域
 * author:chutianhua
 * date:2018/6/27
 *
 * **/
function setCsSmOrderDictionary(){
	var params = {
		headerValue:false
	}
	//设置客户身份
	uceDictCombobox("workorderStatusId","CUSTOMER_IDENTITY",params);
	//设置优先级
	uceDictCombobox("prioritySelectId","PRCESS_PRIORITY_PROCESSING",params);
	setCsSmOrderTypeParent();//设置工单类型
	setAdministrativeDivisionValue(senderPCCT,"sendProvinceId","sendCityId","sendAreaId","sendTownId");//发件地址
	setAdministrativeDivisionValue(receiverPCCT,"receiveProvinceId","receiveCityId","receiveAreaId","receiveTownId");//收件地址
}
/***
 * 新建工单工单类型加载方法功能区域
 * author:chutianhua
 * date:2018/6/27
 *
 * **/
function setCsSmOrderTypeParent(){
	var orderTypeParam = {
		data:{
			kind: 0
		}
	};
	setCsSmOrderTypeSelect('orderTypeId','orderChilTypeId',orderTypeParam);
}

/***
 * 新建工单客服工单编码生成方法功能区域
 * author:chutianhua
 * date:2018/6/27
 *
 * **/
function setCsWoCustSerCode() {
	var url = G_CTX_PATH + '/cs/HomeScreenPopup/getCsWoCustSerCode.do';
	$.ajax({
		type: 'get',
		url: url,
		success: function (data) {
			var jsonObject = $.parseJSON(data);
			$.each(jsonObject, function (index, row) {
				$('#csWoCustSerCodeId').val(row.csWoCustSerCode);
			});
		}
	});
}
/***
 * 新建工单相关运单信息回填方法功能区域--运单搜所按钮使用
 * author:chutianhua
 * date:2018/6/27
 *
 * **/
function  setCsWoCusSerForWaybillInformation(value){
	var data = {billCode:value}
	var url=G_CTX_PATH+"/cs/CsCommon/findWaybllInfo.do";//工单查询url
	uceAjax(url,data,function(res){
		if(res.success){
			if(res.data!=null){
				$('#expressPackingId').textbox('setValue',res.data.goodsName);//快件包装--运单信息没有
				$('#expressInteriorId').textbox('setValue',res.data.goodsName);//快件內物--运单信息暂时先用gondsName
				$('#senderId').textbox('setValue',res.data.sender);//发件人
				$('#senderTelId').textbox('setValue',res.data.senderTel);//发件号码
				$('#receiverId').textbox('setValue',res.data.receiver);//收件人
				$('#receiverTelId').textbox('setValue',res.data.receiverTel);//收件号码
				$('#receiveAddressId').textbox('setValue',res.data.receiverAddress);//收件详细地址
				$('#sendAddressId').textbox('setValue',res.data.senderAddress);//发件详细地址
				//设置行政区划（运单信息暂时无法返回，预留）
				/*//发件地址
				 $('#sendProvinceId').combobox('setValue',res.data.senderTel);//发件省
				 $('#sendCityId').combobox('setValue',res.data.receiver);//发件市
				 $('#sendAreaId').combobox('setValue',res.data.receiverTel);//发件县
				 $('#sendTownId').combobox('setValue',res.data.receiverAddress);//发件乡
				 //收件地址
				 $('#receiveProvinceId').combobox('setValue',res.data.senderTel);//收件省
				 $('#receiveCityId').combobox('setValue',res.data.receiver);//收件市
				 $('#receiveAreaId').combobox('setValue',res.data.receiverTel);//收件县
				 $('#receiveTownId').combobox('setValue',res.data.receiverAddress);//收件乡*/

			}

		}

	},"POST");
}
/***
 * 新建工单运单号搜所方法功能区域
 * author:chutianhua
 * date:2018/6/27
 *
 * **/
function waybillInformationSearchbox(){
	if(!$('#csSmOrderWaybillNumId').searchbox('isValid')){
		return;
	}
	var value = $('#csSmOrderWaybillNumId').searchbox("getValue");
	if(value == ""){
		showInfoMsg("运单编号为空",'提示');
	}else{
		//已完结工单参数
		var haveDoneParams = {
			waybillNum:value,
			status: "5",
			source:"0"
		}
		//处理中工单
		var noDoneWorkParams = {
			waybillNum:value,
			statusMul: "0,1,2,3,4",
			source:"0"
		}
		//运单号查询
		waybillInformation(value);
		//物流信息查询
		logisticsInformationListLoading(value);
		//问题信息
		problemInformationListLoading(value);
		//发放记录查询
		recordsListLoading (value);
		//子单记录
		childInformationListLoading(value);
		//已完结工单列表加载数据
		$('#haveDoneWorkList').datagrid('load',haveDoneParams);
		//处理中工单列表加载数据
		$('#nohaveDoneWorkList').datagrid('load',noDoneWorkParams);
		//增加新建工单相关运单信息回填
		// setCsWoCusSerForWaybillInformation(value);
	}
}
/***
 * 新建工单保存方法功能区域---核心功能
 * author:chutianhua
 * date:2018/6/27
 *
 * **/
function addCsSmOrder(selDutyOrg){
	//设置工单类型和子类型冗余字段
	setCsWoCustSerRedundantField();
	//设置客户编码
	var custCode = $('#customerCodeId').textbox('getValue');
	$('#csSmOrderCustomerCodeId').val(custCode);
	//设置客户等级
	var custGrage = $('#customerInformationCustomerGradeSelectId').combobox('getValue');
	$("#customerGradeId").val(custGrage);
	//设置第一节点处理人
	$("#selDutyOrgId").val(selDutyOrg);
	//手动选择责任人
	var url =G_CTX_PATH+"/cs/CsWoCustSer/save.do";
	var data =serializeFormObj("newCsSmOrderFromId");
	//设置提交状态
	data.flag=0;
	uceAjax(url,data,function (result) {
		if(result.success){
			showInfoMsg("工单保存成功！",function(){
				/*window.parent.window.vm.rlliu*/closeCurrentTab();
			});
		}else{
			errorAlert("工单保存失败，请重新添加");
		}
	},"POST");

}
/***
 *x新建工单校验后保存方法
 * author:chutianhua
 * date:2018/6/26
 * **/
function saveorsubmitCsWoCustSer() {
	//工单数据校验
	var WoCustSerFormValidate = $("#newCsSmOrderFromId").form('validate');
	if(WoCustSerFormValidate){
		var waybillCode=$("#csSmOrderWaybillNumId").val();
		if(waybillCode == "" || waybillCode == null || waybillCode == undefined){//无运单号时校验是否需要输入运单
			if(checkRequireWayBillNum()){
				errorAlert("请输入运单号");
				return;
			}
		}else{//有运单时校运单的准确性，并判断工单是否为同类创建,是否允许创建
			var isReallyWaybillCode =checkWaybillCode();
			if(!isReallyWaybillCode){
				errorAlert("请填写正确的运单号");
				return;
			}
			//工单创建规则校验，呼叫中心工单：同一个来电号码，同一个运单，同一个类型，不可创建同类工单
			var sameCsWoCustSer =checkSameCsWoCustSer();
			if(sameCsWoCustSer){
				errorAlert("同一个来电号码，同一个运单，同一个类型，不可创建同类工单");
				return;
			}
			//验证是否允许创建
			var canCreate =checkCanCreate();
			if(canCreate==1){
				errorAlert("只有做签收扫描之后才能创建");
				return;
			}else if(canCreate==2){
				errorAlert("只有签收扫描或派件之后才能创建");
				return;
			}
		}

		validateSel();
	}
}

/**
 * 错误信息提示
 * @param errorMessage
 */
function errorAlert(errorMessage){
	showInfoMsg(errorMessage);
	$('#addCsSmOrderId').linkbutton('enable');
	//来电手机号查询方法，刷新客户信息
	queryCustomerInformation();
}

function validateSel(){
	//校验是否需手动选择第一节点处理机构,暂不处理
	var selType = checkRequireSelOrg();
	if(selType=="0"){
		addCsSmOrder();
	}else{
		//openDialog("dlgSelOrg", '手动选择责任方网点/中心');
		var title ="手动选择责任方";
		if(selType=="11"){
			title=title+"网点"
		}else if(selType=="12"){
			title=title+"中心"
		}else if(selType=="3"){
			title=title+"网点/中心"
		}

		//初始化责任方处理网点
		initSelDutyOrg(selType,title);
		createDialog("dlgSelOrg", title);
	}

}

/***
 *责任方网点弹窗选择确认
 * author:chutianhua
 * date:2018/6/26
 * **/
function sure(){
	var selDutyBranch =$("#selDutyBranch").combobox('getValue');
	if(selDutyBranch!=""){
		closeDialog('dlgSelOrg');//关闭弹窗
		addCsSmOrder(selDutyBranch);
	}
}
/***
 *设置新建工单冗余字段
 * author:chutianhua
 * date:2018/6/26
 * **/
function setCsWoCustSerRedundantField(){
	//设置新建工单客户编码
	$('#csSmOrderCustomerCodeId').val( $('#customerCodeId').val());
	//设置受理客服
	getUserLoginName();
	//设置工单类型和子类型冗余字段
	$("#orderTypeNameId").val($("#orderTypeId").combobox("getText")); //父类型
	$("#orderTypeChildNameId").val($("#orderChilTypeId").combobox("getText"));  //子类型
	//设置省市县乡冗余字段（发件地址）
	$("#sendProvinceNameId").val($("#sendProvinceId").combobox("getText")); //
	$("#sendCityNameId").val($("#sendCityId").combobox("getText"));  //
	$("#sendAreaNameId").val($("#sendAreaId").combobox("getText")); //
	$("#sendTownNameId").val($("#sendTownId").combobox("getText"));  //
	//设置省市县乡冗余字段（收件地址）
	$("#receiveProvinceNameId").val($("#receiveProvinceId").combobox("getText")); //
	$("#receiveCityNameId").val($("#receiveCityId").combobox("getText"));  //
	$("#receiveAreaNameId").val($("#receiveAreaId").combobox("getText")); //
	$("#receiveTownNameId").val($("#receiveTownId").combobox("getText"));  //
}
/***
 *设置新建工单受理客服name和code
 * author:chutianhua
 * date:2018/6/26
 * **/
function getUserLoginName(){
	var url =G_CTX_PATH+'/login/getCurrentUser.do';
	uceAjax(url,{},function(date){
		$('#acceptServicerId').val(date.empCode);
		$('#acceptServicerNameId').val(date.empName)
	});
}


/**
 * 验证是否允许创建工单
 * 由工单子类型和运单决定
 * 0允许 1：无签收扫描不允许（虚假签收） 2：无签收扫描/无派件不允许（不送货上门）*/
function checkCanCreate(){
	var canCreate =0;
	var url = G_CTX_PATH + "/cs/CsWoCustSer/checkCanCreate.do";
	var checkData ={
		orderChilType:$("#newCsSmOrderFromId  #orderChilTypeId").combobox("getValue"),
		wayBillNum: $("#newCsSmOrderFromId #csSmOrderWaybillNumId").val(),
		source:0
	}
	$.ajax({
		type: "GET",
		url: url,
		data: checkData,
		async: false,
		success : function(result){
			if(result.data!=0){
				canCreate=result.data;
			}
		}
	});
	return canCreate;
}
/******************* 新建工单功能区域--- 结束---*author：chutianhua* date:2018/6/26** ***************************************/








/************************************************* 来电弹屏右下角tab功能区域 ------------开始---------------*author:chutianhua*date:2018/6/26* *************************/

/**
 * 物流信息列表加载
 * @param value
 */
function  logisticsInformationListLoading(value){

	var columns = [[
		{field:'createDate',title: '日期',width: 80},
		{field:'createTime',title: '时间',width: 80},
		{field:'trackMessage',title: '跟踪记录',width: 300}
	]]
	var dataGridParams = {
		url:G_CTX_PATH+"/cs/HomeScreenPopup/findTraceInfo.do",
		Method:'POST',
		queryParams:{billCode:value},
		singleSelect : 'true',
		fitColumns : 'true',
		pagination : false
	}
	newloadGrid('logisticsInformationList', columns, dataGridParams);
}

/**
 * 统一搜所运单号查询
 * @param value
 */
function waybillInformation(value){
	var data ={billCode:value};
	//获取对应的运单的值
	var url=G_CTX_PATH+"/cs/CsCommon/findWaybllInfo.do";//工单查询url
	uceAjax(url,data,function(res){
		if(res.success){
			if(res.data!=null){
				$('#waybillNumId').text(value);
				res.data.sendAccSiteName == null ? $('#sendAccSiteId').text(""):$('#sendAccSiteId').text(res.data.sendAccSiteName);
				res.data.sendupAdd == null ? $('#sendupAddId').text(""): $('#sendupAddId').text(res.data.sendupAdd);
				res.data.signer == null ? $('#signerId').text("") :  $('#signerId').text(res.data.signer);
				res.data.billTypeName == null ? $('#billType').text("") : $('#billType').text(res.data.billTypeName);
				res.data.carriage == null ? $("#carriageId").text("") : $('#carriageId').text(res.data.carriage);
				res.data.realWeight == null ?  $('#realWeightId').text("") : $('#realWeightId').text(res.data.realWeight);
				res.data.bulkWeight == null ?  $('#bulkWeightId').text("") : $('#bulkWeightId').text(res.data.bulkWeight);
				res.data.goodsPayment == null ? $('#goodsPaymentId').text("") : $('#goodsPaymentId').text(res.data.goodsPayment);
				res.data.signTime == null ?  $('#signTimeId').text("") :  $('#signTimeId').text(timestampToTime(res.data.signTime));
				res.data.recOrgCode == null ? $('#recOrgCodeId').text("") : $('#recOrgCodeId').text(res.data.recOrgCode);
				res.data.sendDate == null ? $('#sendDateId').text("") : $('#sendDateId').text(timestampToTime(res.data.sendDate));
				res.data.qty == null ? $('#qtyId').text(""): $('#qtyId').text(res.data.qty);
				res.data.operateEmpName == null ? $('#operateEmpNameId').text(""): $('#operateEmpNameId').text(res.data.operateEmpName);
				res.data.receiver == null ? $('#signManId').text(""): $('#signManId').text(res.data.receiver);
                res.data.sendOrgName == null ? $('#sendOrgName').text(""): $('#sendOrgName').text(res.data.sendOrgName);


				/**
				 * 回写运单信息
				 * chenqinglong
				 * 20180628
				 */
				// $('#expressPackingId').textbox('setValue',res.data.goodsName);//快件包装--运单信息没有
				$('#expressInteriorId').textbox('setValue',res.data.goodsName);//快件內物--运单信息暂时先用gondsName
				$('#senderId').textbox('setValue',res.data.sender);//发件人
				$('#senderTelId').textbox('setValue',res.data.senderTel);//发件号码
				$('#receiverId').textbox('setValue',res.data.receiver);//收件人
				$('#receiverTelId').textbox('setValue',res.data.receiverTel);//收件号码
				$('#receiveAddressId').textbox('setValue',res.data.receiverAddress);//收件详细地址
				$('#sendAddressId').textbox('setValue',res.data.senderAddress);//发件详细地址
				//设置行政区划（运单信息暂时无法返回，预留）

				senderPCCT["provinces"] = res.data.sendProvinceCode;
				senderPCCT["citys"] = res.data.sendCityCode;
				senderPCCT["countys"] = res.data.sendCountyCode;
				// senderPCCT["towns"] = res.data.sendCountyCode;

				receiverPCCT["provinces"] = res.data.recProvinceCode;
				receiverPCCT["citys"] = res.data.recCityCode;
				receiverPCCT["countys"] = res.data.recCountyCode;
				// receiverPCCT["towns"] = res.data.recCountyCode;

				//发件地址
				 $('#sendProvinceId').combobox('setValue',res.data.sendProvinceCode);//发件省
				 // $('#sendCityId').combobox('setValue',res.data.sendCityCode);//发件市
				 // $('#sendAreaId').combobox('setValue',res.data.sendCountyCode);//发件县
				 // $('#sendTownId').combobox('setValue',res.data.receiverAddress);//发件乡
				 //收件地址
				 $('#receiveProvinceId').combobox('setValue',res.data.recProvinceCode);//收件省
				 // $('#receiveCityId').combobox('setValue',res.data.recCityCode);//收件市
				 // $('#receiveAreaId').combobox('setValue',res.data.recCountyCode);//收件县
				 // $('#receiveTownId').combobox('setValue',res.data.receiverAddress);//收件乡
			}
		}
	},"POST");
}

/**
 * 时间戳格式化
 * @param timestamp
 * @returns {*}
 */
function timestampToTime(timestamp) {
    var date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000

    y = date.getFullYear() + '-';
	mm = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
	d = date.getDate() + ' ';
    h = date.getHours() + ':';
    m = date.getMinutes() + ':';
    s = date.getSeconds();
    return y+mm+d+h+m+s;
}

/**
 * 问题信息
 * @param value
 */
function problemInformationListLoading (value){
	var columns = [[
		{field:'woCode',title: '工单编号',width: 150,
			formatter: function(value, row, index){
				return '<a href="javascript:(0)" onclick="orderRecords(' + value + ')">'+value+'</a>';
			}},
		{field:'createTime',title: '时间',width: 150, formatter: formatTime},
		{field:'orderTypeName',title: '工单类型',width: 150, formatter: formatTip},
		{field:'orderChilTypeName',title: '工单子类型',width: 150, formatter: formatTip},
		{field:'submitterName',title: '发起站点',width: 150},
		{field:'currentDealEmpName',title: '接收站点',width: 150},
		{field:'orderTitle',title: '内容记录',width: 150}
	]]
	var dataGridParams = {
		url:G_CTX_PATH+"/cs/HomeScreenPopup/findProblemInfo.do",
		Method:'POST',
		queryParams:{waybillNum:value},
		singleSelect : 'true',
		fitColumns : 'true'
	}
	newloadGrid('problemInformationList', columns, dataGridParams);
}

/***
 * 发放记录方法功能区域
 * author:chutianhua
 * date:2018/6/26
 * **/
function recordsListLoading (value){
	var columns = [[
		{field:'startNo',title: '起始单号',width: 150},
		{field:'endNo',title: '终止单号',width: 150},
		{field:'inoutTypeName',title: '类型', width: 60},
		{field:'dispenseDate',title: '发放/转让时间', width: 150,formatter:function(value,row,index){
			return  formatData(value)
		}},
		{field:'dispenseOrgName',title: '使用网点', width: 100},
		{field:'useOrgName',title: '跟踪记录',width: 200,formatter:function (value,row,index) {
			//跟踪记录预留方法
		}}
	]]
	var dataGridParams = {
		url:G_CTX_PATH+"/cs/HomeScreenPopup/findDispenseList.do",
		Method:'POST',
		queryParams:{billCode:value},
		singleSelect : 'true',
		fitColumns : 'true'
	}
	newloadGrid('recordsListLoadingId', columns, dataGridParams);
}

/**
 * 子单信息
 * @param value
 */
function childInformationListLoading (value){
	var columns = [[
		{field:'childBillCode',title: '运单编号',width: 150,
			formatter: function(value, row, index){
				return '<a href="javascript:(0)" onclick="childTrace(' + value + ')">'+value+'</a>';
			}
		}
	]]
	var dataGridParams = {
		url:G_CTX_PATH+"/cs/CsCommon/findChildWaybllInfo.do",
		Method:'POST',
		queryParams:{billCode:value},
		singleSelect : 'true',
		fitColumns : 'true'
	}
	newloadGrid('childInformationList', columns, dataGridParams);

	$("#zidanxinxi").show();
	$("#zidanxinxiwuliu").hide();
}

/**
 * 子单物流轨迹
 * @param value
 */
function childTrace(value){
	$("#zidanxinxi").hide();
	$("#zidanxinxiwuliu").show();

	var columns = [[
		{field:'createDate',title: '日期',width: 80},
		{field:'createTime',title: '时间',width: 80},
		{field:'trackMessage',title: '跟踪记录',width: 300}
	]]
	var dataGridParams = {
		url:G_CTX_PATH+"/cs/HomeScreenPopup/findTraceInfo.do",
		Method:'POST',
		queryParams:{billCode:value},
		singleSelect : 'true',
		fitColumns : 'true',
		pagination : false
	}
	newloadGrid('childLogisticsInformationList', columns, dataGridParams);
}

/**
 * 问题件流转记录
 */
function orderRecords(value){
	$("#wentijian").hide();
	$("#wentijianliuzhuan").show();

	var columns = [[
		{field:'operationName',title: '名称',width: 150},
		{field:'createTime',title: '创建时间',width: 150, formatter: formatTime},
		{field:'submitTime',title: '处理时间',width: 150, formatter: formatTime},
		{field:'handlerDepartName',title: '处理部门',width: 150},
		{field:'currentHandlerName',title: '处理人',width: 150},
		{field:'handleExplain',title: '处理意见',width: 150}
	]]
	var dataGridParams = {
		url:G_CTX_PATH+"/cs/HomeScreenPopup/findProblemRecordsInfo.do",
		Method:'POST',
		queryParams:{woCode:value},
		singleSelect : 'true',
		fitColumns : 'true',
		pagination : false
	}
	newloadGrid('problemRecordsList', columns, dataGridParams);
}


function zidanTabsBack() {
	$("#zidanxinxi").show();
	$("#zidanxinxiwuliu").hide();
}

function wentijianTabsBack() {
	$("#wentijian").show();
	$("#wentijianliuzhuan").hide();
}

/************************************************* 来电弹屏右下角功能tab区域 -----------------结束--------------*author:chutianhua*date:2018/6/26* *************************/



/************************************************* 来电弹屏公共方法区域 开始*author:chutianhua*date:2018/6/26* *************************/
/***
 * 获取form数据方法功能区域
 * author:chutianhua
 * date:2018/6/26
 * **/
function getFormData(formId){
	var dataformInit = $("#"+formId).serializeArray();
	var jsonTextInit = JSON.stringify({ dataform: dataformInit });
	return jsonTextInit;
}

/***
 * 判断form数据是否发生改变方法功能区域
 * author:chutianhua
 * date:2018/6/26
 * **/
function comparsionFormData(usedData,newData) {
	if(usedData==newData) {

		return false;


	}else{

		return true;


	}
}

/***
 * 页面设置行政区划方法功能区域
 * author:chutianhua
 * date:2018/6/26
 * **/
function setAdministrativeDivisionValue(defaultPar,provinceId, cityId, countyId, townId) {
	areaCascade(defaultPar,provinceId, cityId, countyId, townId);
}

/***
 * 页面初始化来电弹屏所有字典项方法功能区域
 * author:chutianhua
 * date:2018/6/26
 * **/
function initializeDictionary() {
	//初始化来电弹屏所有字典项方法
	var url = G_CTX_PATH + "/dictData/findByTypesCodes.do";
	initDictDatas("CUST_SER_STATUS,CUSTOMER_TYPE,CUSTOMER_GRADE,SYS_SEX,TRUE_OR_FALSE,PRCESS_PRIORITY_PROCESSING,WO_SOURCE,S_TYPE,TRUE_OR_FALSE,CUSTOMER_IDENTITY", {url: url});
}

/***
 * 重写优速加载省市县三级联动方法,增加加载乡镇功能,三级改为四级联动
 * author:chutianhua
 * date:2018/6/26
 * **/
function areaCascade(defaultPar,provinceId, cityId, regionId,townId, params) {
	var townAreaCode;
	var url = G_CTX_PATH + "/omg/OmgArea/getAreaCascade.do";
	if (!provinceId) {
		console.error("provinceId不能为空");
		return;
	}
	$("#" + provinceId).combobox({
		width: params && !isNaN(params.width) ? params.width : undefined,
		height: params && !isNaN(params.height) ? params.height : undefined,
		panelWidth: params && !isNaN(params.panelWidth) ? params.panelWidth : undefined,
		panelHeight: params && !isNaN(params.panelHeight) ? params.panelHeight : undefined,
		valueField: params && params.valueField ? params.valueField : 'areaCode',
		textField: params && params.textField ? params.textField : 'areaName',
		url: params && params.url ? params.url : url,
		editable: params && params.editable == false ? false : true,
		onBeforeLoad: function (param) {
			param.areaType = 2;
		},
		onLoadSuccess:function (data) {
			$("#" + provinceId).combobox("setValue",defaultPar["provinces"]);
			defaultPar["provinces"] = "";
		},
		onSelect: !cityId || cityId == null ? function () {
		} : function (record) {
			console.log(record);
			if (regionId && regionId != null) {
				$("#" + regionId).combobox('clear');
			}
			$("#" + cityId).combobox("clear");
			$("#" + cityId).combobox({
				valueField: params && params.valueField ? params.valueField : 'areaCode',
				textField: params && params.textField ? params.textField : 'areaName',
				url: params && params.url ? params.url : url,
				editable: params && params.editable == true ? true : false,
				onBeforeLoad: function (param) {
					param.areaType = 3;
					param.parentAreaCode = record.areaCode;
				},
				onLoadSuccess:function (data) {
					$("#" + cityId).combobox("setValue",defaultPar["citys"]);
					defaultPar["citys"] = "";
				},

				onSelect: !regionId || regionId == null ? function () {
				} : function (record) {
					$("#" + regionId).combobox("clear");
					$("#" + regionId).combobox({
						valueField: params && params.valueField ? params.valueField : 'areaCode',
						textField: params && params.textField ? params.textField : 'areaName',
						url: params && params.url ? params.url : url,
						editable: params && params.editable == true ? true : false,
						onBeforeLoad: function (param) {
							param.areaType = 4;
							param.parentAreaCode = record.areaCode;
						},
						onLoadSuccess:function (data) {
							$("#" + regionId).combobox("setValue",defaultPar["countys"]);
							defaultPar["countys"] = "";
						},
						onSelect: function (record) {
							townAreaCode = record.areaCode;
							//调用加载乡镇方法
							loadTownValue(defaultPar,url, townId, params,townAreaCode)
						}

					})
				}
			})
		}

	})
}

/***
 *加载乡镇数据(combobox只能嵌套三次，否侧无法访问最后一个combobox)
 * author:chutianhua
 * date:2018/6/26
 * **/
function loadTownValue(defaultPar,url, townId, params, townAreaCode) {
	var url = G_CTX_PATH + "/omg/OmgArea/getAreaCascade.do";
	$("#" + townId).combobox({
		valueField: params && params.valueField ? params.valueField : 'areaCode',
		textField: params && params.textField ? params.textField : 'areaName',
		url: params && params.url ? params.url : url,
		onBeforeLoad: function (param) {
			param.areaType = 5;
			param.parentAreaCode = townAreaCode;
		},
		onLoadSuccess:function (data) {
			$("#" + townId).combobox("setValue",defaultPar["towns"]);
			defaultPar["towns"] = "";
		},
	})
}
/***
 * dialog弹窗初始化弹出位置调整方法功能区域
 * author:chutianhua
 * date:2018/6/26
 * **/
function  createDialog(id, title){
	$('#'+id).dialog({
		title: title,
		align : 'center',
		// 弹框top=滚动条到页面顶部的距离+（页面显示的高度-弹框的高度）/2
		top:$(document).scrollTop()+($(window).height()-450)*0.5,
		cache: false,
		modal: true,
		onClose:function(){
			$('#addCsSmOrderId').linkbutton('enable');
		}
	});
	$('#'+id).dialog('open');
}

//初始化责任方网点
function initSelDutyOrg(selType,title){
	var par = {};
	if(selType == 3){
		par["orgTypeStr"] = "20,30";
	}else if (selType == 11){
		par["orgTypeStr"] = "30";
	}else if (selType == 12){
		par["orgTypeStr"] = "20";
	}else if (selType == 14){
		par["orgTypeStr"] = "20,21,30,40";
	}
	$("#selDutyBranch").combobox({
		url:G_CTX_PATH + '/cs/omg/org/findOrgCmsByOrgType.do',
		prompt:title,
		queryParams:par,
		valueField:'baseOrgCode',
		textField:'orgFullName'
	})
	
	// $("#selDutyBranch").combotree({
	// 	url:G_CTX_PATH + '/cs/omg/org/findAsyOrgTree.do',
	// 	prompt:title,
	// 	onBeforeLoad:function(node,param){
	// 		param.orgFlag='CMS';
	// 		if(node){
	// 			param.orgCode=node.id;
	// 			if(node.orgType == 10){//如果当前节点是总部，下一级节点查财务中心
	// 				param.orgType = 20;
	// 			}else{//否则查网点
	// 				param.orgType = 30;
	// 			}
	// 		}else{
	// 			param.orgCode=null;
	// 			param.orgType=null;
	// 		}
	// 	},
	// 	onSelect:function(node){
	// 		if(selType=="3"){
	// 			//手动选择网点/中心
	// 			if(node.orgType != 30 && node.orgType!=20){
	// 				showInfoMsg("请选择网点或财务中心");
	// 				$("#selDutyBranch").combotree('setValue', '');
	// 				$('#selDutyOrgType').val("");
	// 				$('#selDutyOrgId').val("");
	// 				return false;
	// 			}
	// 		}else if(selType=="11"){
	// 			if(node.orgType != 30 ){
	// 				//手动选择网点
	// 				showInfoMsg("请选择网点");
	// 				$("#selDutyBranch").combotree('setValue', '');
	// 				$('#selDutyOrgType').val("");
	// 				$('#selDutyOrgId').val("");
	// 				return false;
	// 			}
	// 		}else if(selType=="12"){
	// 			if(node.orgType != 20 ){
	// 				//手动选择中心
	// 				showInfoMsg("请选择财务中心");
	// 				$("#selDutyBranch").combotree('setValue', '');
	// 				$('#selDutyOrgType').val("");
	// 				$('#selDutyOrgId').val("");
	// 				return false;
	// 			}
	// 		}else if(selType=="14"){
	// 			//网服特配，不能选总部
	// 			if(node.orgType == 10 ){
	// 				showInfoMsg("不能选择总部");
	// 				$("#selDutyBranch").combotree('setValue', '');
	// 				$('#selDutyOrgType').val("");
	// 				$('#selDutyOrgId').val("");
	// 				return false;
	// 			}
	// 		}
	// 		$('#selDutyOrgType').val(node.orgType);
	// 	}
	// })
}
/************************************************* 来电弹屏公共方法区域--------------结束---------------*author:chutianhua*date:2018/6/26* *************************/





/************************************************* 来电弹屏公共校验方法区域----------------开始---------------*author:chutianhua*date:2018/6/26* *************************/

/***
 *新建工单信息
 * 保存和提交前校验运单号是否必填
 * 校验通过直接保存/提交
 * 校验功能区域
 * author:chutianhua
 * date:2018/6/26
 * **/
function checkRequireWayBillNum(){
	var billRequire =false;
	var url = G_CTX_PATH + "/cs/CsWoCustSer/checkRequireWayBillNum.do";
	var checkData ={
		orderType:$("#orderTypeId").combobox("getValue"),
		orderChilType:$("#orderChilTypeId").combobox("getValue"),
		source:0
	}
	$.ajax({
		type: "GET",
		url: url,
		data: checkData,
		async: false,
		success : function(result){
			if(result.data==1){
				billRequire=true;
			}
		}
	});
	return billRequire;

}

/**提交前校验
 * 手动选择第一节点处理机构类型
 * 0:不手动选择3:中心或网点 11：网点12：中心
 * */
function checkRequireSelOrg(){
	var selType =0;
	var url = G_CTX_PATH + "/cs/CsWoCustSer/checkManualSelMechanism.do";
	var checkData ={
		orderChilType:$("#orderChilTypeId").combobox("getValue"),
		source:0
	}
	$.ajax({
		type: "GET",
		url: url,
		data: checkData,
		async: false,
		success : function(result){
			if(result.data!="0"){
				selType=result.data;
			}
		}
	});
	return selType;
}
/***
 * 客户信息手机号校验功能区域
 * author:chutianhua
 * date:2018/6/26
 * **/
function checkCustomerPhone(phone) {
	var res = false;
	var data = {phone: phone};
	var url = G_CTX_PATH + "/cs/CsCustomerInfomation/getCustomerInformationQueryPhone.do";
	$.ajax({
		type: "POST",
		url: url,
		data: data,
		async: false,
		success: function (data) {
			var result = data;
			if (result.success) {
				if (result.data != null) {
					res = true;
				}
			}
		}
	});
	return res;
}
/***
 * 新建工单校验运单号功能区域
 * author:chutianhua
 * date:2018/6/26
 * **/
function checkWaybillCode(){
	var res =false;
	var waybillCode=$("#csSmOrderWaybillNumId").val();
	if(waybillCode!="" &&waybillCode!=null){
		var data ={billCode:waybillCode};
		//获取对应的运单的值
		var url=G_CTX_PATH+"/cs/CsCommon/findWaybllInfo.do";//工单查询url
		$.ajax({
			type: "POST",
			url: url,
			data: data,
			async:false,
			success : function(data){
				var result = data;
				if(result.success){
					if(result.data!=null){
						res = true;
					}
				}
			}
		});
	}
	return res;
}

/************************************************* 来电弹屏公共校验方法区域结束*author:chutianhua*date:2018/6/26* *************************/
